package comparer

import (
	"log"
	
	"mig/pkg/data"
	"mig/pkg/reader"
	"mig/pkg/types"
)

type BloomFilterComparer struct {
	chunkSize  int64
	maxWorkers int
}

func NewBloomFilterComparer(chunkSize int64, maxWorkers int) *BloomFilterComparer {
	return &BloomFilterComparer{
		chunkSize:  chunkSize,
		maxWorkers: maxWorkers,
	}
}

func (c *BloomFilterComparer) Compare(src data.Database, tgt data.Database,
	srcInfo *types.IntegrityInfo) (*types.CompareResult, error) {
	rd := reader.NewDefaultReader(tgt, c.chunkSize, c.maxWorkers)
	tgtInfo, err := rd.Read(types.AlgorithmBloomFilter)
	if err != nil {
		log.Printf("reader error: %s", err)
		return nil, err
	}

	return srcInfo.Compare(tgtInfo), nil
}
